library BurstFire initializer init requires LegacySystem, AmmoAPI

	private function BurstFireConditions takes nothing returns boolean
		local integer i = GetSpellAbilityId()
		return (i=='ACbc' or i=='A01Q')
	endfunction

	private function BurstFire takes nothing returns nothing
		local player p = GetTriggerPlayer()
		local integer i = GetConvertedPlayerId(p)
		local integer id = GetSpellAbilityId()
		local unit u = GetTriggerUnit()
		local effect sfx

		if not IsUnitType(u,UNIT_TYPE_HERO) then
			// do nothing, just let it burst default
		elseif (id=='A01Q' and GetPrimaryAmmoRounds(p)>15) or (id=='ACbc' and GetPrimaryAmmoRounds(p)>10+GetUnitAbilityLevel(u,'ACbc')*5) then
			if id=='A01Q' then
				call AddPrimaryAmmo(u, 0, -15)
			else
				call AddPrimaryAmmo(u, 0, - (10+GetUnitAbilityLevel(u,'ACbc')*5))
			endif
			set sfx = AddSpecialEffectTarget( "Doodads\\LordaeronSummer\\Props\\SmokeSmudge\\SmokeSmudge0.mdl",u,"weapon" )
			call PolledWait(12.)
			call DestroyEffect(sfx)
		else
			call IssueImmediateOrder(u,"holdposition")
			call DisplayTimedTextToPlayer( p, 0.0, 0.0, 2.0, "Insufficient Fuel." )
		endif

		set sfx = null
		set u = null
		set p = null
	endfunction

	private function init takes nothing returns nothing
		local trigger t
		set t = CreateTrigger(  )
		call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)	
		call TriggerAddCondition( t, Condition( function BurstFireConditions ) )
		call TriggerAddAction( t, function BurstFire )
	endfunction
endlibrary